package com.c611.smartclassroom.ali.lot;

import com.aliyun.openservices.iot.api.Profile;
import com.aliyun.openservices.iot.api.message.MessageClientFactory;
import com.aliyun.openservices.iot.api.message.api.MessageClient;
import com.aliyun.openservices.iot.api.message.callback.MessageCallback;
import com.aliyun.openservices.iot.api.message.entity.MessageToken;

import java.io.UnsupportedEncodingException;

//订阅设备的上行数据消息
public class HTTP {
    static String point = "https://ilop.iot-as-http2.cn-shanghai.aliyuncs.com:443";
    static String AppKey = "29146184";
    static String AppSecret = "13de03e39dfc788d76096961275118f3";
    public static void main(String[] args) throws UnsupportedEncodingException {
        Profile profile = Profile.getAppKeyProfile(point, AppKey, AppSecret);
        MessageCallback messageCallback = new MessageCallback() {
            public Action consume(MessageToken messageToken) {
                System.out.println("receive : " + new String(messageToken.getMessage().getPayload()));
                return Action.CommitSuccess;
            }
        };

        MessageClient messageClient = MessageClientFactory.messageClient(profile);
        messageClient.setMessageListener(messageCallback);
        messageClient.connect(messageCallback);

        try
        {
            System.in.read();
        } catch (Exception e) {}
    }
}
